package com.company.jdk8;
import  org.junit.Test;

import javax.sql.rowset.spi.SyncResolver;
import java.io.PrintStream;
import java.util.Comparator;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @ProjectName: 复习java
 * @Package: com.company.jdk8
 * @ClassName: method
 * @Author: wym
 * @Date: 2020/9/13 21:02
 * @Version: 1.0
 */
public class method {
    @Test
    public  void  test(){
        /**
         * 方法引用 ::
         * 类或对象 :: 方法名
         *
         * 对象:: 非静态方法
         * 类:: 静态方法
         * 类::非静态方法
         *Consumer 中的 void accept(T t)
         * PrintStream 中的void println(T t)
         */
        Consumer<String> consumer= System.out::println;
        consumer.accept("test");
        PrintStream printStream=System.out;
        //对象:: 实例方法
        //Consumer void accept(T t)
        //PrintStream void println(T t)
        Consumer<String> con2=printStream::print;
        con2.accept("beiji");
    }
    //类:: 静态方法
    //Comparator 中 int compare(T t1,T t2);
    //Integer 中 int compare(T t1,T t2);
    @Test
    public void test3(){
        Comparator<Integer> comparator=(t1,t2)->Integer.compare(t1,t2);
        Comparator<Integer> comparator1=Integer::compareTo;
        System.out.println(comparator.compare(12,22));
        System.out.println(comparator1.compare(12,3));
    }
    @Test
    public void test4(){
        Function<Double,Long> func=new Function<Double, Long>() {
            @Override
            public Long apply(Double aDouble) {
                return null;
            }
        };
        //类::实例方法
        //Function R apply(T t)
        //Long round(R r)
        Function<Double,Long> func1=b->Math.round(b);

        Function<Double,Long> func2=Math::round;
    }

    /**
     * 类调用非静态方法
     *       实例方法（）
     *  Comparator 中的 int comapre(T t1 ,T t2)
     *
     */
    @Test
    public void  test5(){
        //方法 引用构造器 和 数组 引用构造器 ::new
        Comparator<String> comparator=(s1,s2)->s1.compareTo(s2);
        System.out.println(comparator.compare("abc","abd"));
        System.out.println("*********************");
        Comparator<String> comparator1 = String::compareTo;
        Comparator<String> com2=String::compareTo;
        System.out.println(com2.compare("abc","abm"));
    }

    @Test
    public void test6(){
        BiPredicate<String,String> pre1 = (s1, s2) -> s1.equals(s2);
        System.out.println(pre1.test("abc","abc"));

        System.out.println("*******************");
        BiPredicate<String,String> pre2 = String :: equals;
        System.out.println(pre2.test("abc","abd"));
    }

    /**
     * Funcation中的
     * Function中的R apply(T t)
     * Employee中的String getName();
     */
    @Test
    public void test7(){
        Employee jerry = new Employee(1000, "Jerry", 23, 6000);
        Function<Employee, String> func1=employee -> {
            String name = employee.getName();
            return name;
        };
        System.out.println(func1.apply(jerry));
        System.out.println("*******************");
        Function<Employee,String> func2 = Employee::getName;
        System.out.println(func2.apply(jerry));
    }

}
